import java.util.Arrays;

public class MyStack {

    public int[] elem;
    public int usedSize;

    public MyStack() {
        this.elem = new int[5];
    }

    public void push(int val) {
        if (isFull()) {
            this.elem = Arrays.copyOf(this.elem, 2*this.elem.length);
        }
        this.elem[usedSize++] = val;
        //usedSize++;
    }

    private boolean isFull() {
        return usedSize == this.elem.length;
    }

    public int pop() {
        if (Empty()) {
            throw new RuntimeException("栈为空！");
        }
        int ret = this.elem[usedSize-1];
        usedSize--;
        return ret;
    }

    public boolean Empty() {
        return usedSize == 0;
    }

    public int peek() {
        if (Empty()) {
            throw new RuntimeException("栈为空！");
        }
        return this.elem[usedSize-1];
    }

    public int getUsedSize() {
        return usedSize;
    }

}
